package com.bigdata.service.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.bigdata.common.annotation.RepeatSubmit;
import com.bigdata.common.annotation.Log;
import com.bigdata.common.core.controller.BaseController;
import com.bigdata.common.core.domain.PageQuery;
import com.bigdata.common.core.domain.R;
import com.bigdata.common.core.validate.AddGroup;
import com.bigdata.common.core.validate.EditGroup;
import com.bigdata.common.core.validate.QueryGroup;
import com.bigdata.common.enums.BusinessType;
import com.bigdata.common.utils.poi.ExcelUtil;
import com.bigdata.service.domain.vo.PointTransactionsVo;
import com.bigdata.service.domain.bo.PointTransactionsBo;
import com.bigdata.service.service.IPointTransactionsService;
import com.bigdata.common.core.page.TableDataInfo;

/**
 * 积分交易明细
 *
 * @author ruoyi
 * @date 2025-07-15
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/service/transactions")
public class PointTransactionsController extends BaseController {

    private final IPointTransactionsService iPointTransactionsService;

    /**
     * 查询积分交易明细列表
     */
    @SaCheckPermission("service:transactions:list")
    @GetMapping("/list")
    public TableDataInfo<PointTransactionsVo> list(PointTransactionsBo bo, PageQuery pageQuery) {
        return iPointTransactionsService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出积分交易明细列表
     */
    @SaCheckPermission("service:transactions:export")
    @Log(title = "积分交易明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(PointTransactionsBo bo, HttpServletResponse response) {
        List<PointTransactionsVo> list = iPointTransactionsService.queryList(bo);
        ExcelUtil.exportExcel(list, "积分交易明细", PointTransactionsVo.class, response);
    }

    /**
     * 获取积分交易明细详细信息
     *
     * @param transactionId 主键
     */
    @SaCheckPermission("service:transactions:query")
    @GetMapping("/{transactionId}")
    public R<PointTransactionsVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String transactionId) {
        return R.ok(iPointTransactionsService.queryById(transactionId));
    }

    /**
     * 新增积分交易明细
     */
    @SaCheckPermission("service:transactions:add")
    @Log(title = "积分交易明细", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PointTransactionsBo bo) {
        return toAjax(iPointTransactionsService.insertByBo(bo));
    }

    /**
     * 修改积分交易明细
     */
    @SaCheckPermission("service:transactions:edit")
    @Log(title = "积分交易明细", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PointTransactionsBo bo) {
        return toAjax(iPointTransactionsService.updateByBo(bo));
    }

    /**
     * 删除积分交易明细
     *
     * @param transactionIds 主键串
     */
    @SaCheckPermission("service:transactions:remove")
    @Log(title = "积分交易明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/{transactionIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] transactionIds) {
        return toAjax(iPointTransactionsService.deleteWithValidByIds(Arrays.asList(transactionIds), true));
    }
}
